﻿using UnityEngine;
using System.Collections;

[USequencerEvent("粒子系统/发射粒子")]
public class USParticleEmitterStartEvent : USEventBase {
	
	public void Update() 
	{
		ParticleSystem particleSystem = AffectedObject.GetComponent<ParticleSystem>();
		
		if(particleSystem)
			Duration = particleSystem.duration + particleSystem.startLifetime;
	}
	
	public override void FireEvent()
	{	
		ParticleSystem particleSystem = AffectedObject.GetComponent<ParticleSystem>();
		if(!particleSystem)
		{
			Debug.Log("AffectedObject缺少ParticleSystem（粒子）系统");
			return;
		}
		
		if(!Application.isPlaying)
			return;
		
		particleSystem.Play();
	}
	
	public override void ProcessEvent(float deltaTime)
	{
		if(Application.isPlaying)
			return;
			
		ParticleSystem particleSystem = AffectedObject.GetComponent<ParticleSystem>();
		particleSystem.Simulate(deltaTime);
	}
	
	public override void StopEvent()
	{
		UndoEvent();
	}
	
	public override void UndoEvent()
	{	
		ParticleSystem particleSystem = AffectedObject.GetComponent<ParticleSystem>();
		particleSystem.Stop();
	}
}
